// Learn TypeScript:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html

import ComponentBase from "../../../../general/Script/component/ComponentBase";
import ToggleButton from "../../../../general/Script/component/toggleButton";
import DataMgr from "../../../../general/Script/mgr/dataManager";
import GameMgr from "../../../../general/Script/mgr/gameManager";
import SoundMgr from "../../../../general/Script/mgr/soundManager";

const {ccclass, property} = cc._decorator;

@ccclass
export default class SettingGame extends ComponentBase {

    effect:cc.Node = null
    music:cc.Node = null

    onLoad(): void {
        super.onLoad();
        
        const effect = DataMgr.Ins().getLocalStorage('effect');
        const music = DataMgr.Ins().getLocalStorage('music');
       
        this.effect.getComponent(ToggleButton).setState(!(effect == -1));
        this.music.getComponent(ToggleButton).setState(!(music == -1));

    }


    effectCallBack(target:cc.Button,data){
        const node = target.node;
        const toggle = node.getComponent(ToggleButton);
        const check = toggle.isCheck();
        toggle.setState(!check);
        DataMgr.Ins().setLocalStorage('effect',!check?1:-1);
        SoundMgr.Ins().setEffect(!check);
    }


    musicCallBack(target:cc.Button,data){
        const node = target.node;
        const toggle = node.getComponent(ToggleButton);
        const check = toggle.isCheck();
        toggle.setState(!check);
        DataMgr.Ins().setLocalStorage('music',!check?1:-1);
        SoundMgr.Ins().setMusic(!check);
    }

    closeSettingCallBack(){
        this.node.active = false;
    }


    
    reGameCallBack(target,data){
        this.node.removeFromParent();
        this.node.destroy()
        GameMgr.Ins().emit('newBlockGame',true);
        
    }

}
